//
//  MyVerticalButton.m
//  Enesco
//
//  Created by niki on 2019/1/31.
//  Copyright © 2019年 aufree. All rights reserved.
//

#import "MyVerticalButton.h"

@implementation MyVerticalButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setupPosition:_distance];
    
    
}
-(void)setDistance:(CGFloat)distance
{
    _distance = distance;
    [self setupPosition:distance];
}
-(void)setupPosition:(float)dis
{
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    
    UIImageView *imgV = self.imageView;
    UILabel *label = self.titleLabel;
    
    
    CGFloat imgW = imgV.frame.size.width;
    CGFloat imgH = imgV.frame.size.height;
    
    CGFloat labelW = label.frame.size.width;
    CGFloat labelH = label.frame.size.height;
    
    
    //图片在上居中对齐；文字在下水平居中对齐
//    self.titleEdgeInsets = UIEdgeInsetsMake(0, -detlaLabel, 0, detlaLabel);
//    self.imageEdgeInsets = UIEdgeInsetsMake(0, detlaImg+6, 0, -detlaImg-6);
    
    self.imageView.frame = CGRectMake((width-imgW)/2, height/2-imgH-dis/2, imgW, imgH);
    
    self.titleLabel.frame = CGRectMake((width-labelW)/2, height/2+dis/2, labelW, labelH);
}
@end
